home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / launchpad-integration / launchpadintegration / urls.pyc (.txt) < prev   
Python Compiled Bytecode  |  2009-10-28  |  3KB  |  88 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import urlparse
  5. import subprocess
  6. import os
  7.  
  8. def showUrl(url, logger = None):
  9.     '''Show the given URL in the user\'s preferred browser.
  10.  
  11.     Currently just shells out to gnome-open, which uses the browser
  12.     picked in the Gnome "preferred applications" control panel.
  13.     If firefox is used open a new window.
  14.     If Gnome is not available it uses the x-www-browser setting
  15.     '''
  16.     if logger:
  17.         logger.info('opening URL %s', url)
  18.     
  19.     if os.environ.get('GNOME_DESKTOP_SESSION_ID') and os.path.exists('/usr/bin/gnome-open'):
  20.         command = [
  21.             'gnome-open',
  22.             url]
  23.         if os.path.exists('/usr/bin/gconftool-2'):
  24.             gconf_key = os.popen('gconftool-2 --get /desktop/gnome/url-handlers/http/command')
  25.             if gconf_key.read().strip() == 'firefox %s':
  26.                 if subprocess.call([
  27.                     'firefox',
  28.                     '-remote',
  29.                     'ping()'], stderr = open('/dev/null', 'w')) == 0:
  30.                     command = [
  31.                         'firefox',
  32.                         '-remote',
  33.                         'openURL(%s, new-window)' % url]
  34.                 else:
  35.                     command = [
  36.                         'firefox',
  37.                         url]
  38.             
  39.         
  40.     elif os.environ.get('KDE_FULL_SESSION') and os.path.exists('/usr/bin/kfmclient'):
  41.         command = [
  42.             'kfmclient',
  43.             'openURL',
  44.             url]
  45.     else:
  46.         command = [
  47.             'x-www-browser',
  48.             url]
  49.     if os.getuid() == 0 and os.environ.has_key('SUDO_USER'):
  50.         command = [
  51.             'sudo',
  52.             '-u',
  53.             os.environ['SUDO_USER']] + command
  54.     
  55.     p = subprocess.Popen(command, close_fds = True, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
  56.     p.communicate()
  57.     return p.returncode
  58.  
  59.  
  60. def launchpadDistroPrefix(facet = None):
  61.     if facet is None:
  62.         prefix = ''
  63.     else:
  64.         prefix = '%s.' % facet
  65.     distro = subprocess.Popen([
  66.         'lsb_release',
  67.         '--id',
  68.         '--short'], stdin = subprocess.PIPE, stdout = subprocess.PIPE).communicate()[0].strip()
  69.     release = subprocess.Popen([
  70.         'lsb_release',
  71.         '--codename',
  72.         '--short'], stdin = subprocess.PIPE, stdout = subprocess.PIPE).communicate()[0].strip()
  73.     return 'https://%slaunchpad.net/%s/%s/' % (prefix, distro.lower(), release)
  74.  
  75.  
  76. def getSourcePackageUrl(pkginfo, facet = None):
  77.     prefix = launchpadDistroPrefix(facet)
  78.     return urlparse.urljoin(prefix, '+source/%s/' % pkginfo.sourcepackage)
  79.  
  80.  
  81. def getInfoUrl(pkginfo):
  82.     return urlparse.urljoin(getSourcePackageUrl(pkginfo, 'answers'), '+gethelp')
  83.  
  84.  
  85. def getTranslateUrl(pkginfo):
  86.     return getSourcePackageUrl(pkginfo, 'translations')
  87.  
  88.